---
layout: "default"
title: "repeatElement"
description: "Swift documentation for 'repeatElement': Creates a collection containing the specified number of the given element."
keywords: "repeatElement,func,swift,documentation"
root: "/v3.0"
---

<div class="declaration" id="func-repeatelement-t_-t-count_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-repeatelement-t_-t-count_-int">func repeatElement&lt;T&gt;(<wbr>_:<wbr> T, count: Int)</a>
        
<div class="comment collapse" id="comment-func-repeatelement-t_-t-count_-int"><div class="p">
    <p>Creates a collection containing the specified number of the given element.</p>

<p>The following example creates a <code>Repeated&lt;Int&gt;</code> collection containing five
zeroes:</p>

<pre><code class="language-swift">let zeroes = repeatElement(0, count: 5)
for x in zeroes {
    print(x)
}
// 0
// 0
// 0
// 0
// 0</code></pre>

<p><strong>Parameters:</strong>
  <strong>element:</strong> The element to repeat.
  <strong>count:</strong> The number of times to repeat <code>element</code>.
<strong>Returns:</strong> A collection that contains <code>count</code> elements that are all
  <code>element</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func repeatElement&lt;T&gt;(_ element: T, count n: Int) -&gt; Repeated&lt;T&gt;</code>
    
    
</div></div>
</div>
